package tools

import (
	"fmt"
	"time"
)

type TimeMeasure struct {
	TimeStart time.Time
	TimeEnd   time.Time
	Duration  time.Duration
	Msg       string
	Work      bool
}

func NewTimeMeasure(msg string, on bool) *TimeMeasure {
	return &TimeMeasure{
		Msg:  msg,
		Work: on,
	}
}

func (t *TimeMeasure) Start() {
	t.TimeStart = time.Now()
}

func (t *TimeMeasure) End() {
	t.TimeEnd = time.Now()
	if t.Work {
		t.Duration = t.TimeEnd.Sub(t.TimeStart)
		Msg := fmt.Sprintf("%s Time Duration: %v", t.Msg, t.Duration.Milliseconds())
		fmt.Println(Msg)
	}
}
